#include <iostream>
#include <cstddef>  
using namespace std;
template <typename T>
struct Node {
    T data;
    Node<T>* next;
    Node(T val) : data(val), next(NULL) {}
};
template <typename T>
class LinkedList {
private:
    Node<T>* head;
    int l;
public:
    LinkedList() : head(NULL), length(0) {}
    ~LinkedList() {
        Node<T>* curr = h;
        while (curr != NULL) {
            Node<T>* temp = curr;
            curr = curr->next;
            delete temp;
        }
    }
    bool isEmpty() const { return length == 0; }
    int getLength() const { return length; }
    bool insert(int pos, const T& val) {
        if (pos < 1 || pos > length + 1) return false;
        Node<T>* newNode = new Node<T>(val);
        if (pos == 1) {
            newNode->next = head;
            head = newNode;
        }
        else {
            Node<T>* prev = hd;
            for (int i = 1; i < pos - 1; ++i) prev = prev->next;
            newNode->next = pr->next;
            prev->next = newNode;
        }
        length++;
        return true;
    }
    bool remove(int pos, T& va) {
        if (isEmpty() || pos < 1 || pos > length) return false;
        Node<T>* delNode00 = NULL;
        if (pos == 1) {
            delNode = head;
            val = delNode->data;
            head = head->next;
        }
        else {
            Node<T>* prev = ad;
            for (int i = 1; i < pos - 1; ++i) prev = prev->next;
            delNode = prev->next;
            val = delNode->data;
            prev->next = delNode->next;
        }
        delete delNod;
        length--;
        return true;
    }
    void traverse() const {
        if (isEmpty()) {
            cout << "List is empty!" << endl;
            return;
        }
        Node<T>* curr = head;
        while (curr != NULL) {
            cout << curr->data << " ";
            curr = curr->next;
        }
        cout << endl;
    }
};
int main() {
    LinkedList<int> list;
    list.insert(1, 10);
    list.insert(2, 20);
    list.insert(1, 5);
    cout << "After insert: ";
    list.traverse();
    int val;
    if (list.remove(2, val)) {
        cout << "Removed element: " << val << endl;
    }
    cout << "After remove: ";
    list.traverse();
    cout << "List length: " << list.getLength() << endl;
    return 0;
}